#include "player.h"

// eventually you may want to create an update function that does movement and all the other things that need to be done continuously
// including: movement, collision checking, attacking,

player::player(float x, float y, float w, float h)
{
        box_x = x;
        box_y = y;
        box_w = w;
        box_h = h;
        move_speed = .5;
        hp = 30;
        fullhp = 30;
}


void player::giveImage(sf::Texture a)
{
    psprite.setTexture(a);

}

void player::movement()
{
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
    {
      //  cout << "Left key pressed " << endl;
        if (box_x <= 0) // if the left side goes off screen
            box_x = 0; // set the box so it doesnt go off screen
        else
            box_x -= move_speed;
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
    {
       // cout << "Right key pressed " << endl;
        if (box_x+box_w >= SCREEN_W) // if the right side goes out off screen
            box_x = SCREEN_W - box_w; // set the box so it doesnt go out off screen
        else
            box_x += move_speed;

    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
    {
       // cout << "Up key pressed " << endl;
        if (box_y <= 0) // if the right side goes out off screen
            box_y = 0; // set the box so it doesnt go out off screen
        else
            box_y -= move_speed;

    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
    {
        //cout << "Down key pressed " << endl;
        if (box_y+box_h >= SCREEN_H) // if the right side goes out off screen
            box_y = SCREEN_H - box_h; // set the box so it doesnt go out off screen
        else
            box_y += move_speed;

    }

}

void player::drawMe()
{
    // draw texture on sprite
    psprite.setPosition(sf::Vector2f(box_x, box_y));

   // scale texture on sprite
    psprite.setScale(sf::Vector2f(1.0f, 1.0f));

}

void player::updateMe()
{
    drawMe();
    movement();


}

player::~player()
{
    //dtor
}
